/*     */ package com.zimbra.cs.redolog.op;
/*     */ 
/*     */ import com.zimbra.cs.mailbox.MailItem.Type;
/*     */ import com.zimbra.cs.mailbox.Mailbox;
/*     */ import com.zimbra.cs.mailbox.MailboxIndex;
/*     */ import com.zimbra.cs.mailbox.MailboxManager;
/*     */ import com.zimbra.cs.mailbox.MailboxOperation;
/*     */ import com.zimbra.cs.redolog.RedoLogInput;
/*     */ import com.zimbra.cs.redolog.RedoLogOutput;
/*     */ import com.zimbra.cs.redolog.Version;
/*     */ import java.io.IOException;
/*     */ import java.util.EnumSet;
/*     */ import java.util.HashSet;
/*     */ import java.util.Set;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class ReindexMailbox
/*     */   extends RedoableOp
/*     */ {
/*  36 */   private Set<MailItem.Type> types = null;
/*  37 */   private Set<Integer> mItemIds = null;
/*  38 */   private int mCompletionId = 0; @Deprecated
/*  39 */   private boolean mSkipDelete = false;
/*     */   
/*     */   public ReindexMailbox() {
/*  42 */     super(MailboxOperation.ReindexMailbox);
/*     */   }
/*     */   
/*     */   public ReindexMailbox(int mailboxId, Set<MailItem.Type> types, Set<Integer> itemIds, int completionId, boolean skipDelete) {
/*  46 */     this();
/*  47 */     setMailboxId(mailboxId);
/*  48 */     assert ((types == null) || (itemIds == null));
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public boolean deferCrashRecovery()
/*     */   {
/*  57 */     return true;
/*     */   }
/*     */   
/*     */   public void redo() throws Exception
/*     */   {
/*  62 */     Mailbox mbox = MailboxManager.getInstance().getMailboxById(getMailboxId());
/*  63 */     if (this.types != null) {
/*  64 */       mbox.index.startReIndexByType(this.types);
/*  65 */     } else if (this.mItemIds != null) {
/*  66 */       mbox.index.startReIndexById(this.mItemIds);
/*     */     } else {
/*  68 */       mbox.index.startReIndex();
/*     */     }
/*     */   }
/*     */   
/*     */   protected String getPrintableData()
/*     */   {
/*  74 */     StringBuilder sb = new StringBuilder("Completion=" + this.mCompletionId);
/*  75 */     sb.append(" SkipDelete=" + (this.mSkipDelete ? "TRUE" : "FALSE"));
/*  76 */     if (this.mItemIds != null) {
/*  77 */       sb.append(" ITEMIDS[");
/*  78 */       boolean atStart = true;
/*  79 */       for (Integer i : this.mItemIds) {
/*  80 */         if (!atStart) {
/*  81 */           sb.append(',');
/*     */         } else
/*  83 */           atStart = false;
/*  84 */         sb.append(i);
/*     */       }
/*  86 */       sb.append(']');
/*     */       
/*  88 */       return sb.toString(); }
/*  89 */     if (this.types != null) {
/*  90 */       sb.append(" TYPES[");
/*  91 */       sb.append(this.types);
/*  92 */       sb.append(']');
/*     */       
/*  94 */       return sb.toString();
/*     */     }
/*  96 */     return null;
/*     */   }
/*     */   
/*     */   protected void serializeData(RedoLogOutput out)
/*     */     throws IOException
/*     */   {
/* 102 */     if (getVersion().atLeast(1, 9))
/*     */     {
/* 104 */       out.writeInt(this.mCompletionId);
/*     */       
/*     */ 
/* 107 */       if (this.types != null) {
/* 108 */         out.writeBoolean(true);
/* 109 */         int count = this.types.size();
/* 110 */         out.writeInt(count);
/* 111 */         for (MailItem.Type type : this.types) {
/* 112 */           out.writeByte(type.toByte());
/* 113 */           count--;
/*     */         }
/* 115 */         assert (count == 0);
/*     */       } else {
/* 117 */         out.writeBoolean(false);
/*     */       }
/*     */       
/*     */ 
/* 121 */       if (getVersion().atLeast(1, 10)) {
/* 122 */         if (this.mItemIds != null) {
/* 123 */           out.writeBoolean(true);
/* 124 */           int count = this.mItemIds.size();
/* 125 */           out.writeInt(count);
/* 126 */           for (Integer i : this.mItemIds) {
/* 127 */             out.writeInt(i.intValue());
/* 128 */             count--;
/*     */           }
/* 130 */           assert (count == 0);
/*     */         } else {
/* 132 */           out.writeBoolean(false);
/*     */         }
/*     */         
/* 135 */         if (getVersion().atLeast(1, 20)) {
/* 136 */           out.writeBoolean(this.mSkipDelete);
/*     */         }
/*     */       }
/*     */     }
/*     */   }
/*     */   
/*     */   protected void deserializeData(RedoLogInput in)
/*     */     throws IOException
/*     */   {
/* 145 */     if (getVersion().atLeast(1, 9))
/*     */     {
/* 147 */       this.mCompletionId = in.readInt();
/*     */       
/*     */ 
/* 150 */       if (in.readBoolean()) {
/* 151 */         this.types = EnumSet.noneOf(MailItem.Type.class);
/* 152 */         for (int count = in.readInt(); count > 0; count--) {
/* 153 */           this.types.add(MailItem.Type.of(in.readByte()));
/*     */         }
/*     */       } else {
/* 156 */         this.types = null;
/*     */       }
/*     */       
/*     */ 
/* 160 */       if (getVersion().atLeast(1, 10)) {
/* 161 */         if (in.readBoolean()) {
/* 162 */           this.mItemIds = new HashSet();
/* 163 */           for (int count = in.readInt(); count > 0; count--) {
/* 164 */             this.mItemIds.add(Integer.valueOf(in.readInt()));
/*     */           }
/*     */         }
/* 167 */         if (getVersion().atLeast(1, 20)) {
/* 168 */           this.mSkipDelete = in.readBoolean();
/*     */         }
/*     */       } else {
/* 171 */         this.mItemIds = null;
/* 172 */         this.mSkipDelete = false;
/*     */       }
/*     */     }
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/redolog/op/ReindexMailbox.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */